package com.sunny.ynhz.service;

import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.WindowManager;
import android.widget.TextView;

import com.sunny.ynhz.R;
import com.sunny.ynhz.ui.MainActivity;

/**
 * Created by mli on 2016/6/20.
 * http://hiapk.org
 */

public class WarnService extends Service {
    public static final int NOTIFICATION_ID=0x12;
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent,int flags, int startId) {
        return START_STICKY;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        if (Build.VERSION.SDK_INT <Build.VERSION_CODES.JELLY_BEAN_MR2) {
            startForeground(NOTIFICATION_ID, new Notification());
        } else {
            Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class);
            resultIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            PendingIntent resultPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, resultIntent, 0);
            //API 18以上，发送Notification并将其置为前台后，启动InnerService
            Notification.Builder builder = new Notification.Builder(this);
            builder.setSmallIcon(R.mipmap.logo);
            builder.setContentTitle("红河州河长");
            builder.setContentIntent(resultPendingIntent);
            builder.setContentText("您当前正在巡河中,请不要忘记巡河");
            startForeground(NOTIFICATION_ID, builder.build());
        }

    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}
